package com.steam.order.rocket;

import com.steam.order.domain.OrderPetAcquisition;
import com.steam.order.mapper.OrderPetAcquisitionMapper;
import com.steam.order.service.impl.OrderPetAcquisitionServiceImpl;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "delay-topic",consumerGroup = "consumer-group")
public class DelayConsumer implements RocketMQListener<String> {

    @Autowired
    private OrderPetAcquisitionMapper orderPetAcquisitionMapper;

    @Autowired
    private OrderPetAcquisitionServiceImpl orderPetAcquisitionService;

    @Override
    public void onMessage(String message) {
        OrderPetAcquisition order = orderPetAcquisitionMapper.loadByMsgId(Long.valueOf(message));
        if (order != null && order.getState().equals(0)) {
            orderPetAcquisitionService.cancel(order.getId());
        }
    }
}